Docking CDialogBar Horizontally with CToolbar [migrated]

Posted by PSU on Programmers See other posts from Programmers or by PSU
Published on 2012-11-27T19:29:31Z Indexed on 2012/11/27 23:28 UTC
Read the original article Hit count: 121

Filed under:
|
|

I need to display a CToolbar (m_wndToolBar) and a CDialogBar (m_wndDlgBarSid1) horizontally (i.e. next to each other, not above one another). The parent frame is derived from CMDIFrameWnd.

I've tried all sorts of variations to get this to work. While I can properly position the CDialogBar to the right of the CToolbar, I cannot persist the positioning, although the WINDOWPLACEMENT mechanism is working correctly (the registry is written on program exit); whenever the program is run, the CToolbar shows up docked left, and the CDialogBar shows up below it, also docked left. I'm using (perforce) MFC and Visual C++ 6.0. Here's the code, slightly redacted to remove debug printouts and the like:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
   {
      return -1;
   }
   if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME) )
   {
      return -1;      // fail to create
   }
   if (!m_wndDlgBarSid1.Create(this, IDD_DIALOGBAR_SID1, CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
   {
      return -1;        // fail to create
   }

   WINDOWPLACEMENT wp ;
   CString sSection = "DialogBarSettings";
   CString sEntry = "Sid1";
   if ( ReadWindowPlacement( &wp, sSection, sEntry ))
   {
      BOOL bSWP = m_wndDlgBarSid1.SetWindowPlacement( &wp );
      RecalcLayout();
   }

   m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
   m_wndToolBar.GetToolBarCtrl().ModifyStyle( 0, TBSTYLE_FLAT, 0 ) ;
   m_wndDlgBarSid1.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY ) ;

   m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
   EnableDocking(CBRS_ALIGN_ANY);
   DockControlBar(&m_wndToolBar);

   m_wndDlgBarSid1.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
   DockControlBar(&m_wndDlgBarSid1,AFX_IDW_DOCKBAR_TOP);

   return 0;
}

Any thoughts?

© Programmers or respective owner

Related posts about Windows

Related posts about visual-c++